package com.gzyj.jtt808.v2013.protocol.jtt1078;

import com.gzyj.jtt808.utils.HexBytesUtil;
import com.gzyj.jtt808.v2013.Package;
import com.gzyj.jtt808.v2013.enums.BusinessDataType;
import io.netty.buffer.ByteBuf;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
@ApiModel("查询资源列表")
public class JTT808_0x9205 extends Package implements Serializable {


    @ApiModelProperty("通道号")
    public Byte ChannelNo;

    @ApiModelProperty("开始时间")
    public Date BeginTime;

    @ApiModelProperty("结束时间")
    public Date EndTime;

    @ApiModelProperty("报警标志")
    public Long AlarmFlag;
    @ApiModelProperty("音视频资源类型")
    public Byte MediaType;

    @ApiModelProperty("码流类型")
    public Byte StreamType;

    @ApiModelProperty("存储器类型")
    public Byte MemoryType;


    public JTT808_0x9205() {
        super(BusinessDataType.查询资源列表.getCode());
    }

    @Override
    public void encodeImpl(ByteBuf buf) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss");
        buf.writeByte(this.ChannelNo);
        buf.writeBytes(HexBytesUtil.WriteBCD(sdf.format(this.BeginTime),12));
        buf.writeBytes(HexBytesUtil.WriteBCD(sdf.format(this.EndTime),12));
        buf.writeLong(this.AlarmFlag);
        buf.writeByte(this.MediaType);
        buf.writeByte(this.StreamType);
        buf.writeByte(this.MemoryType);
    }

    @Override
    public JTT808_0x9205 decodeImpl(ByteBuf buf) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss");
        this.ChannelNo=buf.readByte();
        try {
            this.BeginTime=sdf.parse(HexBytesUtil.ReadBCD(HexBytesUtil.readByOffset(buf,6),12));
            this.EndTime=sdf.parse(HexBytesUtil.ReadBCD(HexBytesUtil.readByOffset(buf,6),12));
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }

        this.AlarmFlag=buf.readLong();
        this.MediaType=buf.readByte();
        this.StreamType=buf.readByte();
        this.MediaType=buf.readByte();

        return this;
    }


}
